<?php 
echo $javascript->link('jquery-1.4.2');
echo $html->css ( 'tab' );
echo $html->css ( 'schedules' );
?>

<script type="text/javascript">
function listdates()
{
	var cd=$(".nedate").val();
	var s=cd.split("/");
	var cYear=s[0];
	var cMonth=s[1];
	var cDay=s[2];
	if(cMonth<10)
	{
		cMonth2="0"+cMonth;
	}
	else
	{
		cMonth2=cMonth;
	}
	if(cDay<10)
	{
		cDay2="0"+cDay;
	}
	else
	{
		cDay2=cDay;
	}
	var sunday=cYear+"-"+cMonth2+"-"+cDay2;
	var sat=new Date(cYear,cMonth-1,cDay-0+6);
	var satYear=sat.getFullYear();
	var satMonth=sat.getMonth()+1;
	var satDate=sat.getDate();
	if(satMonth<10)
	{
		satMonth2="0"+satMonth;
	}
	else
	{
		satMonth2=satMonth;
	}
	if(satDate<10)
	{
		satDate2="0"+satDate;
	}
	else
	{
		satDate2=satDate;
	}
	var satday=satYear+"-"+satMonth2+"-"+satDate2;
	$.ajax({
        type: "post",
        url: "<?php echo ROOT_WEB_PATH; ?>/schedules/getweekSchedule",
         data: {
			sunday:sunday,
			satday:satday
        },
         dataType:"json",
         success: function(data) {
        	 $("td").html("");
     		for(i=0;i<=6;i++)
     		{
     			var cd=$(".nedate").val();
     			var s=cd.split("/");
     			var cYear=s[0];
     			var cMonth=s[1];
     			var cDay=s[2];
     			var now=new Date(cYear,cMonth-1,cDay-0+i);
     			var nowYear=now.getFullYear();
     			var nowMonth=now.getMonth()+1;
     			var nowDate=now.getDate();
     			
     			if(nowMonth<10)
     			{
     				nowMonth="0"+nowMonth;
     			}
     			if(nowDate<10)
     			{
     				nowDate2="0"+nowDate;
     			}
     			else
     			{
     				nowDate2=nowDate;
         		}
     			var nowday=nowYear+"-"+nowMonth+"-"+nowDate2;
     			var context="<a href='#' style='color:#747474;margin:-24px 0px 0px 80%;position:relative;' class='ind"+nowday+"'>"+nowDate+"</a><a href='#' style='margin:10px;position:relative;' class='add"+nowday+"'><img style='border:0px' src='<?php echo ROOT_WEB_PATH; ?>/app/webroot/img/add_small.gif'></img></a>";
     			$.each(data.rows,function(a,row){
     				var startday=row.startDate;
					var endday=row.endDate;
					var tosd=nowYear+"-"+nowMonth+"-"+nowDate2+" 00:00:00";
					var toed=nowYear+"-"+nowMonth+"-"+nowDate2+" 23:59:59";
					if(startday<=toed&&endday>=tosd)
					{
						var id=row.id;
						var title=row.title;
						var app="<a href='#' style='background-color:#fdfbdb;border:1px solid #e1dea6;color:#6e9bf4;margin:2px;' class='app"+id+"'>"+title+"</a>";
						context=context+app;
					}
     			});
     			$("td:eq("+i+")").html(context);
     		}
     		$("a[class^='ind']").bind("click",function(){
     			var cDay=$(this).attr("class").substring(3);
     			var href="<?php echo ROOT_WEB_PATH; ?>/schedules/daySchedule/"+cDay;
     			window.open(href);
     		});

     		$("a[class^='add']").bind("click",function(){
     			var cDay=$(this).attr("class").substring(3);
     			var href="<?php echo ROOT_WEB_PATH; ?>/schedules/addinit/"+cDay;
     			window.open(href);
     		});

     		$("a[class^='app']").bind("click",function(){
     			var id=$(this).attr("class").substring(3);
     			var href="<?php echo ROOT_WEB_PATH; ?>/schedules/edit/"+id;
     			window.open(href);
     		});
     		
			},
         		error: function(data) {
		         alert("获取数据异常");
			}
     });
}
$(function(){
var d=new Date();
var nowYear=d.getFullYear();
var nowMonth=d.getMonth()+1;
var nowDate=d.getDate();
var nowDay=d.getDay();

var sun=new Date(nowYear,nowMonth-1,nowDate-nowDay);
var sunYear=sun.getFullYear();
var sunMonth=sun.getMonth()+1;
var sunDate=sun.getDate();
var nedate=sunYear+"/"+sunMonth+"/"+sunDate;
$(".nedate").val(nedate);


var monda=new Date(nowYear,nowMonth-1,nowDate-nowDay+1);
var monYear=monda.getFullYear();
var monMonth=monda.getMonth()+1;
var monDate=monda.getDate();

var nod="";
switch(nowDay)
{
	case 0:
		nod="星期日";
		break;
	case 1:
		nod="星期一";
		break;
	case 2:
		nod="星期二";
		break;
	case 3:
		nod="星期三";
		break;
	case 4:
		nod="星期四";
		break;
	case 5:
		nod="星期五";
		break;
	case 6:
		nod="星期六";
		break;
}


//var ndm=nowYear+"年"+nowMonth+"月"+nowDate+"日    "+nod;
var ndm=monYear+"年"+monMonth+"月"+monDate+"日    "+"星期一";
$(".nev").text(ndm);

listdates();

$(".prev").click(function(){
	var cd=$(".nedate").val();
	var s=cd.split("/");
	var cYear=s[0];
	var cMonth=s[1];
	var cDate=s[2];
	var cudate=new Date(cYear,cMonth-1,cDate-7);
	
	var monda=new Date(cYear,cMonth-1,cDate-6);
	var monYear=monda.getFullYear();
	var monMonth=monda.getMonth()+1;
	var monDate=monda.getDate();
	var ndm=monYear+"年"+monMonth+"月"+monDate+"日    "+"星期一";
	$(".nev").text(ndm);
	
	var sunYear=cudate.getFullYear();
	var sunMonth=cudate.getMonth()+1;
	var sunDate=cudate.getDate();
	var nedate=sunYear+"/"+sunMonth+"/"+sunDate;
	$(".nedate").val(nedate);
	listdates();
});



$(".next").click(function(){
	var cd=$(".nedate").val();
	var s=cd.split("/");
	var cYear=s[0];
	var cMonth=s[1];
	var cDate=s[2];
	var cudate=new Date(cYear,cMonth-1,cDate-0+7); 
	var sunYear=cudate.getFullYear();
	var sunMonth=cudate.getMonth()+1;
	var sunDate=cudate.getDate();

	var monda=new Date(cYear,cMonth-1,cDate-0+8);
	var monYear=monda.getFullYear();
	var monMonth=monda.getMonth()+1;
	var monDate=monda.getDate();
	var ndm=monYear+"年"+monMonth+"月"+monDate+"日    "+"星期一";
	$(".nev").text(ndm);
	
	var nedate=sunYear+"/"+sunMonth+"/"+sunDate;
	$(".nedate").val(nedate);
	listdates();
});
});
</script>

<input type="hidden" class="nedate"></input>
<div class="title">
<ul>
	<li class="previmg"><a href="#" class="prev">上一周</a></li>
	<li class="nextimg"><a href="#" class="next">下一周</a></li>
	<li class="nevimg" style="width:37%"><a class="nev"></a> </li>
	<li class="datebutton"><a href="<?php echo ROOT_WEB_PATH; ?>/schedules/addinit/" target="_blank"><?php echo $html->image('add_small.gif', 
		 							array('title'=>'新增日程','border'=>'0' )); ?>&nbsp;新增日程</a></li>			 
	<li class="datebutton"><a href="<?php echo ROOT_WEB_PATH; ?>/schedules/monthSchedule/"><?php echo $html->image('dateicon.gif', 
		 							array('title'=>'月日程','border'=>'0' )); ?>&nbsp;月日程</a></li>
	<li class="datebutton"><a href="<?php echo ROOT_WEB_PATH; ?>/schedules/allinfo/"><?php echo $html->image('dateicon.gif', 
		 							array('title'=>'所有日程','border'=>'0' )); ?>&nbsp;所有日程</a></li>
	<li class="datebutton">
		<a href="<?php echo ROOT_WEB_PATH; ?>/schedulestyles/index/" target="_blank">
							<?php echo $html->image('date_type.gif', 
		 							array('title'=>'类型管理','border'=>'0' )); ?>&nbsp;类型管理</a></li>
	<li class="datebutton">
		<a href="<?php echo ROOT_WEB_PATH; ?>/importances/index/" target="_blank">
							<?php echo $html->image('date_important.gif', 
		 							array('title'=>'重要性管理','border'=>'0' )); ?>&nbsp;重要性管理</a></li>
</ul>
</div>

<table class="datepicker" cellspacing="0" cellpadding="0">
<tr>
<th>星期日</th>
<th>星期一</th>
<th>星期二</th>
<th>星期三</th>
<th>星期四</th>
<th>星期五</th>
<th>星期六</th>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
</table>

